using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VARDV
    {
        public DataRow Convert2ARDV(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryARDV(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ARDMANDANT"] = " ".PadRight(2 ); 
         dwReturn["ARDLO"] = " ".PadRight(2 ); 
         dwReturn["ARDLB"] = " ".PadRight(2 ); 
         dwReturn["ARDMKL"] = " ".PadRight(1 ); 
         dwReturn["ARDMAT"] = " ".PadRight(14 ); 
         dwReturn["ARDMGBIS"] = " ".PadRight(9 ); 
         dwReturn["ARDAENZL"] = " ".PadRight(0 ); 
         dwReturn["ARDAENB"] = " ".PadRight(8 ); 
         dwReturn["ARDAEND"] = " ".PadRight(0 ); 
         dwReturn["ARDNEUB"] = " ".PadRight(8 ); 
         dwReturn["ARDNEUD"] = " ".PadRight(0 ); 
         dwReturn["ARDMGVON"] = " ".PadRight(0 ); 
         dwReturn["ARDCODE"] = " ".PadRight(6 ); 
         dwReturn["ARDDOSYS"] = " ".PadRight(2 ); 
         dwReturn["ARDDOST"] = " ".PadRight(3 ); 
         dwReturn["ARDLTFG"] = " ".PadRight(0 ); 
         dwReturn["ARDDICHTE"] = " ".PadRight(0 ); 
         dwReturn["ARDTOL"] = " ".PadRight(0 ); 
         dwReturn["ARDBESCH"] = " ".PadRight(50 ); 
         dwReturn["ARDKLASSE"] = " ".PadRight(3 ); 
         dwReturn["ARDSMGVON"] = " ".PadRight(0 ); 
         dwReturn["ARDSMGBIS"] = " ".PadRight(0 ); 
         dwReturn["ARDSMG"] = " ".PadRight(0 ); 
         dwReturn["ARDZCODE"] = " ".PadRight(6 ); 
         dwReturn["ARDZMAT"] = " ".PadRight(14 ); 
         dwReturn["ARDZREZART"] = " ".PadRight(1 ); 
         dwReturn["ARDZREZNR"] = " ".PadRight(10 ); 
         dwReturn["ARDZMG"] = " ".PadRight(0 ); 
         dwReturn["ARDZBESCH"] = " ".PadRight(50 ); 
         dwReturn["ARDLP"] = " ".PadRight(8 ); 
         dwReturn["ARDFILLER"] = " ".PadRight(119 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapARDV(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveARDV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryARDV(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapARDV(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertARDV(dwLocal, ITXDBVERSION);
            }
            UpdateARDV(dwLocal);
        }
        public void InsertARDV(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ARDV(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryARDV(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ARDV WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ARDV  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ARDV";
            Return = Result;
            return Return;
        }
        public void DeleteARDV(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ARDV   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateARDV(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ARDV SET "
                    +"ARDMANDANT= :ARDMANDANT,"
                    +"ARDLO= :ARDLO,"
                    +"ARDLB= :ARDLB,"
                    +"ARDMKL= :ARDMKL,"
                    +"ARDMAT= :ARDMAT,"
                    +"ARDMGBIS= :ARDMGBIS,"
                    +"ARDAENZL= :ARDAENZL,"
                    +"ARDAENB= :ARDAENB,"
                    +"ARDAEND= :ARDAEND,"
                    +"ARDNEUB= :ARDNEUB,"
                    +"ARDNEUD= :ARDNEUD,"
                    +"ARDMGVON= :ARDMGVON,"
                    +"ARDCODE= :ARDCODE,"
                    +"ARDDOSYS= :ARDDOSYS,"
                    +"ARDDOST= :ARDDOST,"
                    +"ARDLTFG= :ARDLTFG,"
                    +"ARDDICHTE= :ARDDICHTE,"
                    +"ARDTOL= :ARDTOL,"
                    +"ARDBESCH= :ARDBESCH,"
                    +"ARDKLASSE= :ARDKLASSE,"
                    +"ARDSMGVON= :ARDSMGVON,"
                    +"ARDSMGBIS= :ARDSMGBIS,"
                    +"ARDSMG= :ARDSMG,"
                    +"ARDZCODE= :ARDZCODE,"
                    +"ARDZMAT= :ARDZMAT,"
                    +"ARDZREZART= :ARDZREZART,"
                    +"ARDZREZNR= :ARDZREZNR,"
                    +"ARDZMG= :ARDZMG,"
                    +"ARDZBESCH= :ARDZBESCH,"
                    +"ARDLP= :ARDLP,"
                    +"ARDFILLER= :ARDFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ARDMANDANT", OracleType.NVarChar).Value = dwData["ARDMANDANT"].ToString(); 
          or1.Parameters.Add("ARDLO", OracleType.NVarChar).Value = dwData["ARDLO"].ToString(); 
          or1.Parameters.Add("ARDLB", OracleType.NVarChar).Value = dwData["ARDLB"].ToString(); 
          or1.Parameters.Add("ARDMKL", OracleType.NVarChar).Value = dwData["ARDMKL"].ToString(); 
          or1.Parameters.Add("ARDMAT", OracleType.NVarChar).Value = dwData["ARDMAT"].ToString(); 
          or1.Parameters.Add("ARDMGBIS", OracleType.NVarChar).Value = dwData["ARDMGBIS"].ToString(); 
          or1.Parameters.Add("ARDAENZL", OracleType.NVarChar).Value = dwData["ARDAENZL"].ToString(); 
          or1.Parameters.Add("ARDAENB", OracleType.NVarChar).Value = dwData["ARDAENB"].ToString(); 
          or1.Parameters.Add("ARDAEND", OracleType.NVarChar).Value = dwData["ARDAEND"].ToString(); 
          or1.Parameters.Add("ARDNEUB", OracleType.NVarChar).Value = dwData["ARDNEUB"].ToString(); 
          or1.Parameters.Add("ARDNEUD", OracleType.NVarChar).Value = dwData["ARDNEUD"].ToString(); 
          or1.Parameters.Add("ARDMGVON", OracleType.NVarChar).Value = dwData["ARDMGVON"].ToString(); 
          or1.Parameters.Add("ARDCODE", OracleType.NVarChar).Value = dwData["ARDCODE"].ToString(); 
          or1.Parameters.Add("ARDDOSYS", OracleType.NVarChar).Value = dwData["ARDDOSYS"].ToString(); 
          or1.Parameters.Add("ARDDOST", OracleType.NVarChar).Value = dwData["ARDDOST"].ToString(); 
          or1.Parameters.Add("ARDLTFG", OracleType.NVarChar).Value = dwData["ARDLTFG"].ToString(); 
          or1.Parameters.Add("ARDDICHTE", OracleType.NVarChar).Value = dwData["ARDDICHTE"].ToString(); 
          or1.Parameters.Add("ARDTOL", OracleType.NVarChar).Value = dwData["ARDTOL"].ToString(); 
          or1.Parameters.Add("ARDBESCH", OracleType.NVarChar).Value = dwData["ARDBESCH"].ToString(); 
          or1.Parameters.Add("ARDKLASSE", OracleType.NVarChar).Value = dwData["ARDKLASSE"].ToString(); 
          or1.Parameters.Add("ARDSMGVON", OracleType.NVarChar).Value = dwData["ARDSMGVON"].ToString(); 
          or1.Parameters.Add("ARDSMGBIS", OracleType.NVarChar).Value = dwData["ARDSMGBIS"].ToString(); 
          or1.Parameters.Add("ARDSMG", OracleType.NVarChar).Value = dwData["ARDSMG"].ToString(); 
          or1.Parameters.Add("ARDZCODE", OracleType.NVarChar).Value = dwData["ARDZCODE"].ToString(); 
          or1.Parameters.Add("ARDZMAT", OracleType.NVarChar).Value = dwData["ARDZMAT"].ToString(); 
          or1.Parameters.Add("ARDZREZART", OracleType.NVarChar).Value = dwData["ARDZREZART"].ToString(); 
          or1.Parameters.Add("ARDZREZNR", OracleType.NVarChar).Value = dwData["ARDZREZNR"].ToString(); 
          or1.Parameters.Add("ARDZMG", OracleType.NVarChar).Value = dwData["ARDZMG"].ToString(); 
          or1.Parameters.Add("ARDZBESCH", OracleType.NVarChar).Value = dwData["ARDZBESCH"].ToString(); 
          or1.Parameters.Add("ARDLP", OracleType.NVarChar).Value = dwData["ARDLP"].ToString(); 
          or1.Parameters.Add("ARDFILLER", OracleType.NVarChar).Value = dwData["ARDFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
